package example.demo.forkjoin;

import example.demo.bean.Student;

import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class VoidForkJoinTest {
    public static void main(String[] args) {
        List<Student> students = IntStream.rangeClosed(0, 100)
                .mapToObj(i -> "name" + i)
                .map(s -> new Student(s, Integer.parseInt(s.split("name")[1])))
                .collect(Collectors.toList());
//        students.forEach(System.out::println);

        System.out.println("students.size() = " + students.size());
        ForkJoinPool pool = new ForkJoinPool();
        VoidTask voidTask = new VoidTask(0, students.size() - 1, students);
        ForkJoinTask<Void> submit = pool.submit(voidTask);
        try {
            submit.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        pool.shutdown();
    }
}
